<template>
  <!-- 排序区域 -->
  <div class="sub-sort">
    <div class="sort">
      <a
        :class="{ active: sortField === sort.value }"
        @click="changeSort(sort.value)"
        href="javascript:;"
        v-for="sort in types"
        :key="sort.name"
        >{{ sort.name }}</a
      >
      <!-- <a
        :class="{ active: sortField === 'publishTime' }"
        @click="changeSort('publishTime')"
        href="javascript:;"
        >最新商品</a
      >
      <a
        :class="{ active: sortField === 'orderNum' }"
        @click="changeSort('orderNum')"
        href="javascript:;"
        >最高人气</a
      >
      <a
        :class="{ active: sortField === 'evaluateNum' }"
        @click="changeSort('evaluateNum')"
        href="javascript:;"
        >评论最多</a
      > -->
    </div>
  </div>
</template>
<script>
import { ref, inject } from 'vue'
const sorts = [
  { name: '默认排序', value: null },
  { name: '最新商品', value: 'publishTime' },
  { name: '最高人气', value: 'orderNum' },
  { name: '评论最多', value: 'evaluateNum' }

]
export default {
  setup () {
    // null(默认排序) publishTime(最新), orderNum(人气),  evaluateNum(评论)
    const sortField = ref(null)

    const types = ref(sorts)

    // 获取过滤条件数据
    const filterParams = inject('filterParams')
    function changeSort (sel) {
      // 如果排序未改变停止逻辑
      if (sortField.value === sel) return
      // 添加排序条件
      filterParams.value.sortField = sel
      sortField.value = sel
    }
    return {
      sortField,
      changeSort,
      types
    }
  }
}
</script>
<style scoped lang='less'>
.sub-sort {
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .sort {
    display: flex;
    a {
      height: 30px;
      line-height: 28px;
      border: 1px solid #e4e4e4;
      padding: 0 20px;
      margin-right: 20px;
      color: #999;
      border-radius: 2px;
      position: relative;
      transition: all 0.3s;
      &.active {
        background: @xtxColor;
        border-color: @xtxColor;
        color: #fff;
      }
      .arrow {
        position: absolute;
        border: 5px solid transparent;
        right: 8px;
        &.up {
          top: 3px;
          border-bottom-color: #bbb;
          &.active {
            border-bottom-color: @xtxColor;
          }
        }
        &.down {
          top: 15px;
          border-top-color: #bbb;
          &.active {
            border-top-color: @xtxColor;
          }
        }
      }
    }
  }
  .check {
    .xtx-checkbox {
      margin-left: 20px;
      color: #999;
    }
  }
}
.list-container {
  margin-top: 20px;
  padding: 0 20px;
  background: #fff;
}
</style>
